#include <cstdio>
#include <cstring>

int n, m, cnt, f[ 1 << 14 ];
bool visit[ 1 << 14 ];

void init( )
{
    int i, t, a, b;
    memset( visit, 0, sizeof( visit ) );
    cnt = 0;
    for ( i = 0; i < n; i++ )
    {
        scanf("%d", &t);
        a = 0;
        while ( t-- )
        {
            scanf("%d", &b); b--;
            a |= ( 1 << b );
        }
        if ( !visit[ a ] )
        {
            visit[ a ] = true;
            f[ cnt++ ] = a;
        }
    }
}

void work( )
{
    int i, j, t;
    for ( i = 0; i < cnt; i++ )
        for ( j = 0; j < cnt; j++ )
        {
            t = f[ i ] | f[ j ];
            if ( !visit[ t ] )
            {
                visit[ t ] = true;
                f[ cnt++ ] = t;
            }
        }
    printf("%d\n", cnt);
}

int main( )
{
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        init( );
        work( );
    }
    return 0;
}
